//用户操作URL
var userUrl = rootPath+"/user";
var activityUrl = rootPath + "/activity";
var shequanUrl = rootPath + "/shequan";

$(function() {
	getFamousShequan();
	getHotsAct();
});

//用户登录
function login() {
	//用户名
	var userName = $('#userName').val();
	//密码
	var password = $('#password').val();
	var verifyCode = "abc1";
	if(userName==null||userName==''||userName=='请输入用户名'){
		alert("您还没有填写用户名");
		return;
	}
	if(password==null||password==''||password=='请输入密码'){
		alert("您还没有填写密码");
		return;
	}
	$.ajax({
		url: userUrl+"/login",
		type: "GET",
		data: {'userName':userName,
				'password':password,
				'verifyCode':verifyCode},
		dataType: "json",
		async:false,
		success: function(response){
			if(response.success && response.busiSuccess){
				alert("登录成功");
				window.location.href="";
				
			}else{
				alert("用户名不存在或密码错误");
			}
		},
		error : function(response) {
			alert('登录失败');
		}
	})
};


//获取人气社圈列表
function getFamousShequan(){
	$.ajax({
		url: shequanUrl+"/famous/all",
		type: "GET",
		dataType: "json",
		async:false,
		success: function(response){
			if(response.success && response.busiSuccess){
				//人气社圈列表
				var data = response.data;
				if(data!=null&&data.length>0){
					var famousShequan = null;
					var famousHtml = '';
					for(var i=0;i<data.length; i++){
						famousShequan = data[i];
						famousHtml += '<li class="clearfix mainLListLi">';
						famousHtml +=  '<div class="mainLListImg fl">';
						famousHtml +=  '<a href="#"><img src="'+ rootPath + famousShequan.shequanLogo1 +'" /></a>';
						famousHtml += '</div>';
						famousHtml += '<div class="mainLListCon fl ow">';
						famousHtml += '<h3 class="fs14 pt5 pb5"><a href="###">'+ famousShequan.shequanName +'</a></h3>';
						famousHtml += '<ul class="clearfix">';
						famousHtml += '<li class="mainLListConBr">成员 '+ famousShequan.membersCount +'</li>';
						famousHtml += '<li>活动 '+famousShequan.actCount+'</li> ';
						famousHtml += '</ul>';
						famousHtml += '<ul class="clearfix">';
						famousHtml += '<li class="mainLListConBr">关注 '+ famousShequan.attentionCount +'</li>';
						famousHtml += '<li>友盟社圈'+ famousShequan.firendScoleCount+'</li>';
						famousHtml += '</ul>';
						famousHtml += '<p class="pt5">'+famousShequan.shequanDesc+'</p>';
						famousHtml += '</div>';
						famousHtml += '</li>';
					}
					$('#famousShequan').html(famousHtml);
				}
			}
		},
		error : function(response) {
			alert("数据加载失败1");
		}
	})
}

//获取热门活动
function getHotsAct(){
//	var hotsAct = null;
//	var hotsActHtml = ''
//	hotsActHtml += '<h3 class="pt10 lh20">';
//	hotsActHtml +=  '<a href="#">让我看看你画画的天赋。</a>';
//	hotsActHtml +=  '</h3>';
//	hotsActHtml +=  '<p class="lh20">';
//	hotsActHtml +=  '地点：海淀校区 时间：2月10日 [<a href="#">北京大学动漫社</a>] 1分钟前';
//	hotsActHtml += '</p>';
//	$('#hotsAct').html(hotsActHtml);
//	return;
	$.ajax({
		url: activityUrl+"/hotsAct",
		type: "GET",
		dataType: "json",
		async:false,
		success: function(response){
			if(response.success && response.busiSuccess){
				//人气社圈列表
				var data = response.data;
				if(data!=null&&data.length>0){
					var hotsAct = null;
					var hotsActHtml = '';
					for(var i=0;i<data.length; i++){
						hotsAct = data[i];
						hotsActHtml += '<h3 class="pt10 lh20">';
						hotsActHtml +=  '<a href="#">'+hotsAct.activityName+'</a>';
						hotsActHtml +=  '</h3>';
						hotsActHtml +=  '<p class="lh20">';
						hotsActHtml +=  '地点：'+hotsAct.activityPlace+' 时间：'+ hotsAct.startTime +' [<a href="#">'+hotsAct.shequanName+'</a>] ' + hotAct.pushDate;
						hotsActHtml += '</p>';
					}
					$('#hotsAct').html(hotsActHtml);
				}
			}
		},
		error : function(response) {
			alert("数据加载失败2");
		}
	})
}
